(function(b) {
	b.fn.extend({
		autocomplete : function(a, f) {
			var e = typeof a == "string";
			f = b.extend({}, b.Autocompleter.defaults, {
				url : e ? a : null,
				data : e ? null : a,
				delay : e ? b.Autocompleter.defaults.delay : 10,
				max : f && !f.scroll ? 10 : 150
			}, f);
			f.highlight = f.highlight || function(c) {
				return c
			};
			f.formatMatch = f.formatMatch || f.formatItem;
			return this.each(function() {
				new b.Autocompleter(this, f)
			})
		},
		result : function(a) {
			return this.bind("result", a)
		},
		search : function(a) {
			return this.trigger("search", [ a ])
		},
		flushCache : function() {
			return this.trigger("flushCache")
		},
		setOptions : function(a) {
			return this.trigger("setOptions", [ a ])
		},
		unautocomplete : function() {
			return this.trigger("unautocomplete")
		}
	});
	b.Autocompleter = function(J, O) {
		var S = {
			UP : 38,
			DOWN : 40,
			DEL : 46,
			TAB : 9,
			RETURN : 13,
			ESC : 27,
			COMMA : 188,
			PAGEUP : 33,
			PAGEDOWN : 34,
			BACKSPACE : 8
		};
		var T = b(J).attr("autocomplete", "off").addClass(O.inputClass);
		var L;
		var F = "";
		var I = b.Autocompleter.Cache(O);
		var Q = 0;
		var A;
		var a = {
			mouseDownOnSelect : false
		};
		var D = b.Autocompleter.Select(O, J, R, a);
		var y;
		b.browser.opera && b(J.form).bind("submit.autocomplete", function() {
			if (y) {
				y = false;
				return false
			}
		});
		T.bind(
				(b.browser.opera ? "keypress" : "keydown") + ".autocomplete",
				function(c) {
					Q = 1;
					A = c.keyCode;
					switch (c.keyCode) {
					case S.UP:
						c.preventDefault();
						if (D.visible()) {
							D.prev();
							var d = D.getTerm();
							var e = D.getActive();
							B(0, true, {
								term : d,
								active : e
							})
						} else {
							B(0, true)
						}
						break;
					case S.DOWN:
						c.preventDefault();
						if (D.visible()) {
							D.next();
							var d = D.getTerm();
							var e = D.getActive();
							B(0, true, {
								term : d,
								active : e
							})
						} else {
							B(0, true)
						}
						break;
					case S.PAGEUP:
						c.preventDefault();
						if (D.visible()) {
							D.pageUp();
							var d = D.getTerm();
							var e = D.getActive();
							B(0, true, {
								term : d,
								active : e
							})
						} else {
							B(0, true)
						}
						break;
					case S.PAGEDOWN:
						c.preventDefault();
						if (D.visible()) {
							D.pageDown();
							var d = D.getTerm();
							var e = D.getActive();
							B(0, true, {
								term : d,
								active : e
							})
						} else {
							B(0, true)
						}
						break;
					case O.multiple && b.trim(O.multipleSeparator) == ","
							&& S.COMMA:
					case S.TAB:
					case S.RETURN:
						if (R()) {
							c.preventDefault();
							y = true;
							return false
						}
						break;
					case S.ESC:
						D.hide();
						break;
					default:
						clearTimeout(L);
						L = setTimeout(B, O.delay);
						break
					}
				}).focus(function() {
			Q++
		}).blur(function() {
			Q = 0;
			if (!a.mouseDownOnSelect) {
				C()
			}
		}).click(function() {
			if (Q++ > 1 && !D.visible()) {
				B(0, true)
			}
		}).bind("search", function() {
			var d = (arguments.length > 1) ? arguments[1] : null;
			function c(f, g) {
				var e;
				if (g && g.length) {
					for ( var h = 0; h < g.length; h++) {
						if (g[h].result.toLowerCase() == f.toLowerCase()) {
							e = g[h];
							break
						}
					}
				}
				if (typeof d == "function") {
					d(e)
				} else {
					T.trigger("result", e && [ e.data, e.value ])
				}
			}
			b.each(N(T.val()), function(e, f) {
				P(f, c, c)
			})
		}).bind("flushCache", function() {
			I.flush()
		}).bind("setOptions", function() {
			b.extend(O, arguments[1]);
			if ("data" in arguments[1]) {
				I.populate()
			}
		}).bind("unautocomplete", function() {
			D.unbind();
			T.unbind();
			b(J.form).unbind(".autocomplete")
		});
		function R() {
			var i = D.selected();
			if (!i) {
				return false
			}
			var h = i.result;
			F = h;
			if (O.multiple) {
				var d = N(T.val());
				if (d.length > 1) {
					var c = O.multipleSeparator.length;
					var e = b(J).selection().start;
					var g, f = 0;
					b.each(d, function(k, j) {
						f += j.length;
						if (e <= f) {
							g = k;
							return false
						}
						f += c
					});
					d[g] = h;
					h = d.join(O.multipleSeparator)
				}
				h += O.multipleSeparator
			}
			T.val(h);
			z();
			T.trigger("result", [ i.data, i.value ]);
			return true
		}
		function B(f, d, c) {
			if (A == S.DEL) {
				D.hide();
				return
			}
			var e = (c ? c.term : T.val());
			if (!d && e == F) {
				return
			}
			F = e;
			e = M(e);
			if (e.length >= O.minChars) {
				T.addClass(O.loadingClass);
				if (!O.matchCase) {
					e = e.toLowerCase()
				}
				P(e, K, z, c)
			} else {
				H();
				D.hide()
			}
		}
		function N(c) {
			if (!c) {
				return [ "" ]
			}
			if (!O.multiple) {
				return [ b.trim(c) ]
			}
			return b.map(c.split(O.multipleSeparator), function(d) {
				return b.trim(c).length ? b.trim(d) : null
			})
		}
		function M(e) {
			if (!O.multiple) {
				return e
			}
			var c = N(e);
			if (c.length == 1) {
				return c[0]
			}
			var d = b(J).selection().start;
			if (d == e.length) {
				c = N(e)
			} else {
				c = N(e.replace(e.substring(d), ""))
			}
			return c[c.length - 1]
		}
		function E(e, c, d) {
			if (A != S.BACKSPACE) {
				if (O.autoFill && !d) {
					T.val(e + c.substring(M(F).length));
					b(J).selection(F.length, F.length + c.length)
				} else {
					if (d) {
						T.val(c)
					}
				}
			}
		}
		function C() {
			clearTimeout(L);
			L = setTimeout(z, 200)
		}
		function z() {
			var c = D.visible();
			D.hide();
			clearTimeout(L);
			H();
			if (O.mustMatch) {
				T.search(function(e) {
					if (!e) {
						if (O.multiple) {
							var d = N(T.val()).slice(0, -1);
							T.val(d.join(O.multipleSeparator)
									+ (d.length ? O.multipleSeparator : ""))
						} else {
							T.val("");
							T.trigger("result", null)
						}
					}
				})
			}
		}
		function K(d, e, c) {
			if (e && e.length) {
				if (Q && !c) {
					H();
					D.display(e, d);
					E(d, e[0].value, c);
					D.show()
				} else {
					if (c) {
						H();
						E(d, e[c.active].value, c)
					}
				}
			} else {
				z()
			}
		}
		function P(f, e, h, g) {
			if (!O.matchCase) {
				f = f.toLowerCase()
			}
			var c = I.load(f);
			if (c && c.length) {
				e(f, c, g)
			} else {
				if ((typeof O.url == "string") && (O.url.length > 0)) {
					var d = {
						timestamp : +new Date()
					};
					b.each(O.extraParams, function(j, i) {
						d[j] = typeof i == "function" ? i() : i
					});
					b.ajax({
						mode : "abort",
						port : "autocomplete" + J.name,
						dataType : O.dataType,
						url : O.url,
						data : b.extend({
							q : M(f),
							limit : O.max
						}, d),
						success : function(i) {
							var j = O.parse && O.parse(i) || G(i);
							I.add(f, j);
							e(f, j)
						}
					})
				} else {
					D.emptyList();
					h(f)
				}
			}
		}
		function G(g) {
			var f = [];
			var c = g.split("\n");
			for ( var e = 0; e < c.length; e++) {
				var d = b.trim(c[e]);
				if (d) {
					d = d.split("|");
					f[f.length] = {
						data : d,
						value : d[0],
						result : O.formatResult && O.formatResult(d, d[0])
								|| d[0]
					}
				}
			}
			return f
		}
		function H() {
			T.removeClass(O.loadingClass)
		}
	};
	b.Autocompleter.defaults = {
		inputClass : "ac_input",
		resultsClass : "ac_results1",
		loadingClass : "ac_loading",
		minChars : 1,
		delay : 400,
		matchCase : false,
		matchSubset : true,
		matchContains : false,
		cacheLength : 10,
		max : 100,
		mustMatch : false,
		extraParams : {},
		selectFirst : true,
		formatItem : function(a) {
			return a[0]
		},
		formatMatch : null,
		autoFill : false,
		width : 0,
		multiple : false,
		multipleSeparator : ", ",
		highlight : function(d, a) {
			return d.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("
					+ a.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1")
					+ ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>")
		},
		scroll : true,
		scrollHeight : 180
	};
	b.Autocompleter.Cache = function(p) {
		var m = {};
		var o = 0;
		function k(c, d) {
			if (!p.matchCase) {
				c = c.toLowerCase()
			}
			var e = c.indexOf(d);
			if (p.matchContains == "word") {
				e = c.toLowerCase().search("\\b" + d.toLowerCase())
			}
			if (e == -1) {
				return false
			}
			return e == 0 || p.matchContains
		}
		function l(c, d) {
			if (o > p.cacheLength) {
				a()
			}
			if (!m[c]) {
				o++
			}
			m[c] = d
		}
		function n() {
			if (!p.data) {
				return false
			}
			var e = {}, f = 0;
			if (!p.url) {
				p.cacheLength = 1
			}
			e[""] = [];
			for ( var c = 0, d = p.data.length; c < d; c++) {
				var h = p.data[c];
				h = (typeof h == "string") ? [ h ] : h;
				var i = p.formatMatch(h, c + 1, p.data.length);
				if (i === false) {
					continue
				}
				var r = i.charAt(0).toLowerCase();
				if (!e[r]) {
					e[r] = []
				}
				var g = {
					value : i,
					data : h,
					result : p.formatResult && p.formatResult(h) || i
				};
				e[r].push(g);
				if (f++ < p.max) {
					e[""].push(g)
				}
			}
			b.each(e, function(t, q) {
				p.cacheLength++;
				l(t, q)
			})
		}
		setTimeout(n, 25);
		function a() {
			m = {};
			o = 0
		}
		function j(g, d) {
			var c = [];
			var f = [];
			var h = [];
			for ( var e = 0; e < g.length; e++) {
				var i = g[e].value.toLowerCase();
				if (i.indexOf(d) == 0) {
					c.push(g[e])
				} else {
					if (i.indexOf(" " + d) > 0) {
						f.push(g[e])
					} else {
						if (i.indexOf(d) > 0) {
							h.push(g[e])
						}
					}
				}
			}
			return c.concat(f).concat(h)
		}
		return {
			flush : a,
			add : l,
			populate : n,
			load : function(g) {
				if (!p.cacheLength || !o) {
					return null
				}
				if (!p.url && p.matchContains) {
					var c = [];
					for ( var e in m) {
						if (e.length > 0) {
							var f = m[e];
							b.each(f, function(i, h) {
								if (k(h.value, g)) {
									c.push(h)
								}
							})
						}
					}
					return j(c, g)
				} else {
					if (m[g]) {
						return m[g]
					} else {
						if (p.matchSubset) {
							for ( var d = g.length - 1; d >= p.minChars; d--) {
								var f = m[g.substr(0, d)];
								if (f) {
									var c = [];
									b.each(f, function(i, h) {
										if (k(h.value, g)) {
											c[c.length] = h
										}
									});
									return c
								}
							}
						}
					}
				}
				return null
			}
		}
	};
	b.Autocompleter.Select = function(G, B, z, v) {
		var C = {
			ACTIVE : "ac_over"
		};
		var A, F = -1, t, y = "", a = true, I, w;
		function x() {
			if (!a) {
				return
			}
			I = b("<div/>").hide().addClass(G.resultsClass).css("position","absolute").css("background","white").css("z-index","99").appendTo(document.body);
			w = b("<ul/>").appendTo(I).mouseover(function(c) {
				if (u(c).nodeName && u(c).nodeName.toUpperCase() == "LI") {
					F = b("li", w).removeClass(C.ACTIVE).index(u(c));
					b(u(c)).addClass(C.ACTIVE)
				}
			}).click(function(c) {
				b(u(c)).addClass(C.ACTIVE);
				z();
				B.focus();
				return false
			}).mousedown(function() {
				v.mouseDownOnSelect = true
			}).mouseup(function() {
				v.mouseDownOnSelect = false
			});
			if (G.width > 0) {
				I.css("width", G.width)
			}
			a = false
		}
		function u(c) {
			var d = c.target;
			while (d && d.tagName != "LI") {
				d = d.parentNode
			}
			if (!d) {
				return []
			}
			return d
		}
		function D(e) {
			A.slice(F, F + 1).removeClass(C.ACTIVE);
			E(e);
			var c = A.slice(F, F + 1).addClass(C.ACTIVE);
			if (G.scroll) {
				var d = 0;
				A.slice(0, F).each(function() {
					d += this.offsetHeight
				});
				if ((d + c[0].offsetHeight - w.scrollTop()) > w[0].clientHeight) {
					w.scrollTop(d + c[0].offsetHeight - w.innerHeight())
				} else {
					if (d < w.scrollTop()) {
						w.scrollTop(d)
					}
				}
			}
		}
		function E(c) {
			F += c;
			if (F < 0) {
				F = A.size() - 1
			} else {
				if (F >= A.size()) {
					F = 0
				}
			}
		}
		function J(c) {
			return G.max && G.max < c ? G.max : c
		}
		function H() {
			w.empty();
			var e = J(t.length);
			for ( var d = 0; d < e; d++) {
				if (!t[d]) {
					continue
				}
				var c = G.formatItem(t[d].data, d + 1, e, t[d].value, y);
				if (c === false) {
					continue
				}
				var f = b("<li/>").html(G.highlight(c, y)).addClass(
						d % 2 == 0 ? "ac_even" : "ac_odd").appendTo(w)[0];
				b.data(f, "ac_data", t[d])
			}
			A = w.find("li");
			if (G.selectFirst) {
				A.slice(0, 1).addClass(C.ACTIVE);
				F = 0
			}
			if (b.fn.bgiframe) {
				w.bgiframe()
			}
		}
		return {
			display : function(c, d) {
				F = -1;
				x();
				t = c;
				y = d;
				H()
			},
			next : function() {
				D(1)
			},
			prev : function() {
				D(-1)
			},
			pageUp : function() {
				if (F != 0 && F - 8 < 0) {
					D(-F)
				} else {
					D(-8)
				}
			},
			pageDown : function() {
				if (F != A.size() - 1 && F + 8 > A.size()) {
					D(A.size() - 1 - F)
				} else {
					D(8)
				}
			},
			hide : function() {
				I && I.hide();
				A && A.removeClass(C.ACTIVE);
				F = -1
			},
			visible : function() {
				return I && I.is(":visible")
			},
			current : function() {
				return this.visible()
						&& (A.filter("." + C.ACTIVE)[0] || G.selectFirst
								&& A[0])
			},
			show : function() {
				var c = b(B).offset();
				I
						.css(
								{
									width : typeof G.width == "string"
											|| G.width > 0 ? G.width : b(B)
											.width(),
									top : c.top + B.offsetHeight,
									left : c.left
								}).show();
				if (G.scroll) {
					w.scrollTop(0);
					w.css({
						maxHeight : G.scrollHeight,
						overflow : "auto"
					});
					if (b.browser.msie
							&& typeof document.body.style.maxHeight === "undefined") {
						var e = 0;
						A.each(function() {
							e += this.offsetHeight
						});
						var d = e > G.scrollHeight;
						w.css("height", d ? G.scrollHeight : e);
						if (!d) {
							A.width(w.width() - parseInt(A.css("padding-left"))
									- parseInt(A.css("padding-right")))
						}
					}
				}
			},
			selected : function() {
				var c = A && A.filter("." + C.ACTIVE).removeClass(C.ACTIVE);
				return c && c.length && b.data(c[0], "ac_data")
			},
			emptyList : function() {
				w && w.empty()
			},
			unbind : function() {
				I && I.remove()
			},
			getTerm : function() {
				return y
			},
			getActive : function() {
				return F
			}
		}
	};
	b.fn.selection = function(j, a) {
		if (j !== undefined) {
			return this.each(function() {
				if (this.createTextRange) {
					var c = this.createTextRange();
					if (a === undefined || j == a) {
						c.move("character", j);
						c.select()
					} else {
						c.collapse(true);
						c.moveStart("character", j);
						c.moveEnd("character", a);
						c.select()
					}
				} else {
					if (this.setSelectionRange) {
						this.setSelectionRange(j, a)
					} else {
						if (this.selectionStart) {
							this.selectionStart = j;
							this.selectionEnd = a
						}
					}
				}
			})
		}
		var l = this[0];
		if (l.createTextRange) {
			var p = document.selection.createRange(), k = l.value, m = "<->", o = p.text.length;
			p.text = m;
			var n = l.value.indexOf(m);
			l.value = k;
			this.selection(n, n + o);
			return {
				start : n,
				end : n + o
			}
		} else {
			if (l.selectionStart !== undefined) {
				return {
					start : l.selectionStart,
					end : l.selectionEnd
				}
			}
		}
	}
})(jQuery);
var defVal = $("#lookup_input").val();
var black = "#000";
var gray = "#909090";
var green = "#000077";
var blockSubmit = false;
var urlStatic = "";
if (document.getElementById("urlStatic")) {
	urlStatic = document.getElementById("urlStatic").value
}
$("#lookup_input").click(function(d) {
	var c = d.currentTarget.value;
	if (c === defVal) {
		d.currentTarget.value = "";
		d.currentTarget.style.color = black
	}
}).blur(function(d) {
	var c = d.currentTarget.value;
	if (c === "") {
		d.currentTarget.value = defVal;
		d.currentTarget.style.color = gray
	}
}).focus(function(d) {
	var c = d.currentTarget.value;
	if (c === defVal) {
		d.currentTarget.value = "";
		d.currentTarget.style.color = black
	}
}).keypress(function(c) {
	var d = c.keyCode ? c.keyCode : c.which ? c.which : c.charCode;
	if (d == 13 && !blockSubmit) {
		$("#search-form").submit();
		$("div.ac_results1").css("display", "none")
	}
});
$("#lookup_input").autocomplete(items, {
	minChars : 1,
	width : $.browser.msie ? 438 : 436,
	scrollHeight : 400,
	max : 20,
	matchContains : true,
	selectFirst : false,
	formatItem : function(f, e, d) {
		return f[0]
	}
}).result(function(e, f, d) {
	if (f[1]) {
		blockSubmit = true;
		e.currentTarget.style.color = green;
		window.location.href = f[1]
	}
});